package com.example.boot;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.TemporalAccessorParser;
import org.springframework.format.datetime.standard.TemporalAccessorPrinter;

@org.springframework.context.annotation.Configuration
public class WebMvcConfiguration {

	@org.springframework.context.annotation.Configuration
	public static class WebConfiguration implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer {

		@Override
		public void addFormatters(FormatterRegistry registry) {
			registry.addFormatterForFieldType(LocalDate.class,
					new TemporalAccessorPrinter(DateTimeFormatter.ISO_LOCAL_DATE),
					new TemporalAccessorParser(LocalDate.class, DateTimeFormatter.ISO_LOCAL_DATE));

			registry.addFormatterForFieldType(LocalTime.class,
					new TemporalAccessorPrinter(DateTimeFormatter.ISO_LOCAL_TIME),
					new TemporalAccessorParser(LocalTime.class, DateTimeFormatter.ISO_LOCAL_TIME));

			registry.addFormatterForFieldType(LocalDateTime.class,
					new TemporalAccessorPrinter(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
					new TemporalAccessorParser(LocalDateTime.class, DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		}

	}

}
